
# range           value category  bits for the value
# 0                      0               -
# -1 1                   1              0,1
# -3 -2 2 3              2         00,01,10,11
# -7 -6 -5 -4 4 5 6 7    3  000,001,010,011,100,101,110,111
# ...
# -2^{v}+1 ~ -2^{v-1} 2^{v-1}~2^{v}-1       v 
def getValueCategory(n):
    
    if n == 0:
        return 0
    if n < 0:
        n = -n
    
    ret = 1
    v = 2
    while v <= n:
        ret += 1
        v <<= 1
    
    return ret
    
def getValueBitStr(n):
    if n == 0:
        return ""
    flag = 1
    if n < 0:
        n = -n
        flag = 0
    
    pc = [ '1', '0']
    if flag == 0:
        pc[0] = '0'
        pc[1] = '1'
    
    
    bv = 1
    ans = ""
    
    while n > 0:
        if n & bv != 0:
            n -= bv
            ans = pc[0] + ans
        else:
            ans = pc[1] + ans
        bv <<= 1
    
    
    return ans


    
if __name__ == "__main__":
    for i in range(-8,8):
        print("%d=%s"%(i,getValueBitStr(i)))
    for i in range(-8,8):
        print("%d value category is %d"%(i, getValueCategory(i)))
    
    
    print("-32767 value category is %d"%(getValueCategory(-32767)))
    print("-32767 bit string is %s"%(getValueBitStr(-32767)))